{% extends "./inc/base.html" %}
{% block style%}
<link rel="stylesheet" href="/static/admin/js/datatables/datatables.css" type="text/css"/>
{% endblock %}
{% block content %}
<section class="vbox">
    <header class="header bg-light dk">
        <ul class="nav nav-tabs pull-left">
            <li class="active"><a href="#messages-2" data-toggle="tab" class="groupindex">全部配置</a></li>
            {% for ingredient, amount in config.setup.CONFIG_GROUP_LIST %}
            <li ><a href="#{{ ingredient }}" data-toggle="tab" data-groupid="{{ ingredient }}" class="grouplist"> {{ amount }}</a></li>
            {% endfor %}
        </ul>

    </header>
    <section class="scrollable wrapper">
        <section class="panel panel-default">
            <header class="panel-heading">
                <div class="btn-group pull-right">
                    <a class="btn btn-success btn-xs" href="/admin/setup/add"><i class="fa fa-check-square-o"></i> 添加配置</a>

                </div>
                配置列表
                <i class="fa fa-info-sign text-muted" data-toggle="tooltip" data-placement="bottom" data-title="ajax to load the data."></i>
            </header>
            <div class="table-responsive">
                <table class="table table-striped m-b-none" data-ride="datatables">
                    <thead>
                    <tr>
                        <th  style="width:60px"><label class="checkbox m-n i-checks"><input type="checkbox"><i></i></label></th>
                        <th  style="width:60px">ID</th>
                        <th >名称</th>
                        <th >标题</th>
                        <th>分组</th>
                        <th>类型</th>
                        <th  style="width:160px">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </section>
    </section>
</section>

{% endblock %}
{% block script%}
<script src="/static/admin/js/datatables/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="/static/admin/js/datatables/jquery.csv-0.71.min.js"  type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function() {
       var table = $('[data-ride="datatables"]').DataTable({
            "serverSide": true,
            "ajax": {
                "url": "/admin/setup/groupdata",
                "data": {
                    "user_id": 1
                }
            },
            "sDom": "<'row'<'col-sm-6'l><'col-sm-6'f>r>t<'row'<'col-sm-6'i><'col-sm-6'p>>",
            "sPaginationType": "full_numbers",
            "ordering": false,
            "deferRender": true,
            "aoColumns": [
                { mData: '' },
                { mData: 'id' },
                { mData: 'name' },
                { mData: 'title' },
                { mData: 'group'},
                { mData: 'type'},
                { mData: null}
            ],
            columnDefs: [
                {
                    targets: 0,
                    render: function (data, type, row) {
                       // console.log(data);
                        var html ='<label class="checkbox m-n i-checks"><input type="checkbox" name="post[]"><i></i></label>';
                        return html;
                    }
                },
                {
                    targets: 6,
                    render: function (data, type, row) {
                        //console.log(data);
                        var html = '<a class="btn btn-default btn-xs" href="/admin/setup/edit/?id='+data.id+'">编辑</a> ' +
                                ' <a class="btn btn-default btn-xs del" onclick="del('+ data.id +')">删除</a>';
                        return html;
                    }
                }

            ],
           language: {
               "sProcessing": "处理中...",
               "sLengthMenu": "显示 _MENU_ 项结果",
               "sZeroRecords": "没有匹配结果",
               "sInfo": "显示第 _START_ 至 _END_ 个配置，共 _TOTAL_ 个",
               "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
               "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
               "sInfoPostFix": "",
               "sSearch": "搜索:",
               "sUrl": "",
               "sEmptyTable": "表中数据为空",
               "sLoadingRecords": "载入中...",
               "sInfoThousands": ",",
               "oPaginate": {
                   "sFirst": "首页",
                   "sPrevious": "上页",
                   "sNext": "下页",
                   "sLast": "末页"
               },
               "oAria": {
                   "sSortAscending": ": 以升序排列此列",
                   "sSortDescending": ": 以降序排列此列"
               }
           }
    } );

        $(".groupindex").click(function(){
            table.ajax.url('/admin/setup/groupdata' ).load();
        })
        $(".grouplist").click(function(){
            var groupid=$(this).attr('data-groupid');
            table.ajax.url( '/admin/setup/groupdata?group='+groupid ).load();
        })
    } );

    function del(id) {
        swal({
                    title: "你确定?",
                    text: "你将要删除配置，并且不能恢复!",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的!",
                    cancelButtonText: "就不!",
                    closeOnConfirm: false
                },
                function(){
                    $.ajax({
                        url: "/admin/setup/del",
                        data: {
                            "id": id
                        }, success: function (data) {

                            location.href = "/admin/setup/group";
                        }
                    });

                });

    }
</script>
{% endblock %}
